<!--
* description: 采购管理-总部仓库维护
* author: hzm
* createdDate: 2021-1-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-api-style="'restful'"
    />
    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>

<script>
import { formMixins } from "@/components/mixins/formMixins";
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import { orgApis } from "@/api/paSparePartsManagement";
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: "pickingList",
  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  mixins: [oneTableWithViewTemplateMixins, formMixins],
  data() {
    return {
      editRowData : {},
      dynamicApiConfigs: orgApis.queryWareHouseManageOemPage,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "controlBtn",
                label: "操作", // 操作
                width: 100,
                align: "center",
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "修改", // 编辑
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: (index) => this.edit(index)
                  },
                ],
              },
              {
                prop: "warehouseCode",
                label: "仓库编码",
                align: "center",
              },
              {
                prop: "warehouseName",
                label: "仓库名称",
                align: "center",
              },
              {
                prop: "isCentreCn",
                label: "是否中心库",
                align: "center",
              },
              {
                prop: "isEnableCn",
                label: "状态",
                align: "center",
              },
              {
                prop: "warehouseAddr",
                label: "仓库地址",
                align: "center",
              },
              {
                prop: "remark",
                label: "备注",
                align: "center",
              }
            ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              // 库存状态
              {
                compKey: "compKey1",
                labelName: "仓库编码：",
                codeField: "warehouseCode",
                lookuptype: "VE0212",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                span: 6,
              },
              // 车辆状态
              {
                compKey: "compKey2",
                labelName: "仓库名称：",
                codeField: "warehouseName",
                lookuptype: "VE0207",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
                span: 6,
              },
              // 入库仓库
              {
                compKey: "compKey3",
                labelName: "状态：",
                codeField: "isEnable",
                component: () => import('@/components/org/LookupValue'),
                oFields: 'isEnable,statusText',
                options: [
                  { isEnable: '1', statusText: '启用' },
                  { isEnable: '0', statusText: '停用' }
                ],
                type: 'dropdownList',
                isMust: true,
                span: 6,
              },
              // 审核状态
              {
                compKey: "compKey4",
                labelName: "中心库：",
                codeField: "isCentre",
                component: () => import('@/components/wms/dropdownList/dropdownList'),
                type: 'dropdownList',
                options: [
                  { value: '1', label: '是' },
                  { value: '0', label: '否' }
                ],
                isMust: true,
                span: 6,
              }
            ],
      tableButtons: [
        {
          conmpKey: "btenKey1",
          type: "primary",
          size: "small",
          name: 'search',
          text: "查询",
          clickEvent: () => this.queryTable(1),
          position: "right",
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          name: 'add',
          clickEvent: this.add,
          text: this.$t('sys.button.add'), // 新增
          position: 'right'
        },
        {
          conmpKey: 'btenKey3',
          type: '',
          size: 'small',
          clickEvent: () => this.export(),
          text: this.$t('sys.button.export'),
          name: 'export',
          position: 'right' // 导出
        },
        {
          conmpKey: "btenKey2",
          type: "",
          size: "small",
          text: "重置",
          name: 'reset',
          clickEvent: () => this.reset(),
          position: "right",
        },
      ],
      formField: this.$utils.getFormField(this, {
        warehouseCode: "",
        warehouseName: "",
        isEnable: "",
        isCentre: ""
      }),
    };
  },
  methods: {
    edit(index) {
      this.editPopupsVisible = true
      this.editPopupsState = 'edit'
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
    },
    close(type) {
      this.editPopupsVisible = type
    },
    export(){
      exportExcel(this.formField, orgApis.exportWareHouseManageOem.APIUrl, orgApis.exportWareHouseManageOem.ServiceCode, '总部仓库维护')
    },
  },
  mounted() {
    this.queryTable(1)
  }
};
</script>

<style>
</style>
